<template>
	<div>
		<home-erji-category :erjiCategory="erjiCategory" @getgoodscodedata="getgoodscode"></home-erji-category>
		<home-new-zone :newZonedata="newZonedata"></home-new-zone>
		<classify-list :erjilistid="erjilistid" v-if="goodsCodedatamsg==item.goodsClassCode" v-for="(item,index) in erjiCategory" :key="index" :goodsClassCode="item.goodsClassCode" :ListTop="ListTop"></classify-list>
	</div>
</template>
<script>
	import HomeErjiCategory from "../../../real-components/HomeErjiCategory";
	import HomeNewZone from "../../../real-components/HomeNewZone";
	import CommodityList from "../../../real-components/CommodityList";
	import { translateDetailData } from "@/utils/TranslateDetailDate";
	import ClassifyList from "../ClassifyList";
	import {mapGetters} from "vuex";
	import GoodsClassifyHeader from "../../GoodsClassify/GoodsClassifyHeader";
	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			},
			erjilistid: {
				type: String,
				default: ""
			},
		},
		data() {
			return {
				newZonedata: {
					publicityPicture: "",
					extendField: ""
				},
				erjiCategory: [],
				goodsCodedata: "",
				goodsCodedatamsg: "",
				goodsNewVO: [],
				ListTop: null,
				goodsCodedataArr: [],
				titlelength: [],
				imglength: [],
			}
		},
		methods: {
			getgoodscode(msg) {
				this.goodsCodedatamsg = msg;
			},
			getgoodsCode() {
				this.goodsCodedataArr = []
				this.titlelength = [];
				this.imglength = [];
				if(this.list) {
					for(var i = 0; i < this.list.length; i++) {
						if(this.list[i].relPosition == "TITLE") {
							if(JSON.parse(this.list[i].extendField).selected == 1) {
								this.goodsCodedata = this.list[i].goodsCode
							} else if(JSON.parse(this.list[i].extendField).selected == 2) {
								this.goodsCodedataArr.push(this.list[i].goodsCode)
								this.goodsCodedata = this.goodsCodedataArr[0]
							} else if(JSON.parse(this.list[i].extendField).erjiErjiCategory == 'ribbon') {
								this.erjiCategory.push(this.list[i].relTitle)
							}
							this.titlelength.push(this.list[i])
						}
						if(this.list[i].relPosition == "IMAGE") {
							this.newZonedata.publicityPicture = this.list[i].publicityPicture
							this.newZonedata.extendField = this.list[i].extendField
							this.imglength.push(this.list[i])
						}
						if(this.list[i].relPosition == "GOODS") {
							this.list[i].goodsNewVO.mainPic = this.list[i].publicityPicture
							this.goodsNewVO.push(this.list[i].goodsNewVO)
						}
					};
					if(this.titlelength.length == 0) {
						this.goodsCodedata = ""
					} else if(this.imglength.length == 0) {
						this.newZonedata = {
							publicityPicture: "",
							extendField: ""
						}
					}
				}

			},
			geterjiCategory() {
				//goodsCode==goodsClassCode
				this.erjiCategory = []
				/*for(var i = 0; i < this.classifyList.length; i++) {
					if(this.goodsCodedata == this.classifyList[i].goodsClassCode) {
						for(var j = 0; j < this.classifyList[i].secList.length; j++) {
							this.erjiCategory.push(this.classifyList[i].secList[j])
						}
					}
				}*/
				if(this.goodsCodedataArr && this.goodsCodedataArr.length > 0 && this.classifyList && this.classifyList.length > 0) {
					for(var i = 0; i < this.classifyList.length; i++) {
						if(this.classifyList[i].secList) {
							for(var j = 0; j < this.classifyList[i].secList.length; j++) {
								for(var k = 0; k < this.goodsCodedataArr.length; k++) {
									if(this.goodsCodedataArr[k] == this.classifyList[i].secList[j].goodsClassCode) {
										this.erjiCategory.push(this.classifyList[i].secList[j])
									}
								}
							}
						} else {
							break
						}
					}
					/*this.erjiCategory = this.goodsCodedataArr.map((list) => {
						var findList = this.classifyList.find((item) => {
							return item.goodsclasscode == list
						}) || {}

						return findList
					})
					console.log(this.erjiCategory, 'jjjjjjjjjjjjjjjjjjjjjjjj')*/
				} else if(this.goodsCodedataArr.length == 0 && this.classifyList && this.classifyList.length > 0) {
					for(var i = 0; i < this.classifyList.length; i++) {
						if(this.goodsCodedata == this.classifyList[i].goodsClassCode) {
							for(var j = 0; j < this.classifyList[i].secList.length; j++) {
								this.erjiCategory.push(this.classifyList[i].secList[j])
							}
						}
					}
					if(this.erjiCategory && this.erjiCategory.length > 0) {
						this.goodsCodedatamsg = this.erjiCategory[0].goodsClassCode
					} else {
						this.goodsCodedatamsg = ""
					}
					/*this.erjiCategory = this.classifyList.filter((item) => {
						return this.goodsCodedata == item.parentclasscode
					})*/
				}
			},
			getListTop() {
				this.ListTop = Number(Math.ceil(this.erjiCategory.length / 5) * 30 + 292)
			}
		},
		watch: {
			list(data) {
				if(data) {
					this.getgoodsCode()
					this.geterjiCategory()
					this.getListTop()
				}
			}
		},
		components: {
			HomeNewZone,
			CommodityList,
			HomeErjiCategory,
			ClassifyList,
			GoodsClassifyHeader
		},
		computed: {
			...mapGetters("cjy", [
                /*"classifyData"*/
                "newClassifyData"
            ]),
			classifyList() {
				return this.newClassifyData;
				//return this.$store.state.cjy.classifyList
			}
		},
		created() {

		},
		mounted() {
			this.getgoodsCode()
			this.geterjiCategory()
			this.getListTop()
		},
	}
</script>
<style scoped>

</style>
